package com.haoting.mamba.team.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.haoting.mamba.team.entity.TeamInformationEntity;
import com.haoting.mamba.team.service.TeamInformationService;
import com.haoting.common.utils.PageUtils;
import com.haoting.common.utils.R;



/**
 * 
 *
 * @author tanghao
 * @email 767417609@qq.com
 * @date 2021-03-14 21:09:05
 */
@RestController
@RequestMapping("team/teaminformation")
public class TeamInformationController {
    @Autowired
    private TeamInformationService teamInformationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = teamInformationService.queryPage(params);

        return R.ok().put("page", page);
    }

    //根据id返回名字
    @GetMapping("/findName/{id}")
    public R findName(@PathVariable("id") String id){
        TeamInformationEntity page = teamInformationService.getById(id);
        String name = page.getName();
        return R.ok().put("name", name);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		TeamInformationEntity teamInformation = teamInformationService.getById(id);

        return R.ok().put("teamInformation", teamInformation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TeamInformationEntity teamInformation){
        String id = teamInformationService.saveInformation(teamInformation);
        return R.ok().put("id",id);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TeamInformationEntity teamInformation){
		teamInformationService.updateById(teamInformation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids){
		teamInformationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @GetMapping("/getWestteam")
    public R getWestteam(){
        List<TeamInformationEntity> list = teamInformationService.list(new QueryWrapper<TeamInformationEntity>().eq("division", "西部"));
        return R.ok().put("westteam",list);
    }

    @GetMapping("/getEastteam")
    public R getEastteam(){
        List<TeamInformationEntity> list = teamInformationService.list(new QueryWrapper<TeamInformationEntity>().eq("division", "东部"));
        return R.ok().put("eastteam",list);
    }
}
